<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Favourite extends Model
{
    //
    protected $table = 'favourite';

    protected function getDateFormat()
    {
        return 'U';
    }

    public function user(){
      return $this->hasOne('App\Models\User','uid','uid');
    }

    public function project(){
      return $this->belongsTo('App\Models\Project','post_id','id')->where('model','project');
    }

    /**
     * 获得收藏数
     * @param unknown_type $project_id
     * @param unknown_type $model
     */
  static function getFavouriteCountByPid($post_id,$model){
  	$count = self::where('post_id',$post_id)->where('model',$model)->count();
  	return $count?$count:0;
  }
}
